home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Source Code / MAP Viewer / Entity.h < prev    next >
C/C++ Source or Header  |  2003-10-09  |  5KB  |  220 lines

  1. /*
  2. Half-Life MAP viewing utility.
  3. Copyright (C) 2003  Ryan Samuel Gregg
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #pragma once
  21. #include "stdafx.h"
  22. #include "WorldObject.h"
  23. #include "ArgVal.h"
  24. #include "Brush.h"
  25. #include "Frustum.h"
  26. #include "TextureManager.h"
  27.  
  28. __gc class CEntity : public CWorldObject
  29. {
  30. private:
  31.     Color3uc Color;
  32.     bool bCulled;
  33.     BoundingBox Box;
  34.     ArrayList *ArgVals;
  35.     ArrayList *Brushes;
  36.  
  37. public:
  38.     CEntity(CConfig *Config) : CWorldObject(Config)
  39.     {
  40.         bCulled = false;
  41.  
  42.         Brushes = new ArrayList();
  43.         ArgVals = new ArrayList();
  44.     }
  45.  
  46.     void SetColor(unsigned char R, unsigned char G, unsigned char B)
  47.     {
  48.         Color.R = R;
  49.         Color.G = G;
  50.         Color.B = B;
  51.     }
  52.  
  53.     void AddBrush(CBrush *Brush)
  54.     {
  55.         Brushes->Add(Brush);
  56.     }
  57.  
  58.     void AddArgVal(CArgVal *ArgVal)
  59.     {
  60.         ArgVals->Add(ArgVal);
  61.     }
  62.  
  63.     ArrayList *GetArgVals()
  64.     {
  65.         return ArgVals;
  66.     }
  67.  
  68.     ArrayList *GetBrushes()
  69.     {
  70.         return Brushes;
  71.     }
  72.  
  73.     String *GetName()
  74.     {
  75.         CArgVal* ArgVal;
  76.         for(int i = 0; i < ArgVals->Count; i++)
  77.         {
  78.             ArgVal = static_cast<CArgVal*>(ArgVals->get_Item(0));
  79.             if(ArgVal->GetArg()->ToLower()->Equals("classname"))
  80.             {
  81.                 return ArgVal->GetVal();
  82.             }
  83.         }
  84.  
  85.         return S"unknowen";
  86.     }
  87.  
  88.     int GetBrushCount()
  89.     {
  90.         return Brushes->Count;
  91.     }
  92.  
  93.     void UpdateBoundingBoxes()
  94.     {
  95.         if(Brushes->Count == 0)
  96.             return;
  97.  
  98.         CBrush *Brush;
  99.         BoundingBox BrushBox;
  100.  
  101.         Brush = static_cast<CBrush*>(Brushes->get_Item(0));
  102.         Brush->UpdateBoundingBoxes();
  103.         BrushBox = Brush->GetBoundingBox();
  104.         
  105.         Box.vNegBound.X = BrushBox.vNegBound.X;
  106.         Box.vNegBound.Y = BrushBox.vNegBound.Y;
  107.         Box.vNegBound.Z = BrushBox.vNegBound.Z;
  108.         Box.vPosBound.X = BrushBox.vPosBound.X;
  109.         Box.vPosBound.Y = BrushBox.vPosBound.Y;
  110.         Box.vPosBound.Z = BrushBox.vPosBound.Z;
  111.  
  112.         for(int i = 1; i < Brushes->Count; i++)
  113.         {
  114.             Brush = static_cast<CBrush*>(Brushes->get_Item(i));
  115.  
  116.             Brush->UpdateBoundingBoxes();
  117.             BrushBox = Brush->GetBoundingBox();
  118.  
  119.             if(BrushBox.vNegBound.X < Box.vNegBound.X)
  120.                 Box.vNegBound.X = BrushBox.vNegBound.X;
  121.  
  122.             if(BrushBox.vNegBound.Y < Box.vNegBound.Y)
  123.                 Box.vNegBound.Y = BrushBox.vNegBound.Y;
  124.  
  125.             if(BrushBox.vNegBound.Z < Box.vNegBound.Z)
  126.                 Box.vNegBound.Z = BrushBox.vNegBound.Z;
  127.  
  128.             if(BrushBox.vPosBound.X > Box.vPosBound.X)
  129.                 Box.vPosBound.X = BrushBox.vPosBound.X;
  130.  
  131.             if(BrushBox.vPosBound.Y > Box.vPosBound.Y)
  132.                 Box.vPosBound.Y = BrushBox.vPosBound.Y;
  133.  
  134.             if(BrushBox.vPosBound.Z > Box.vPosBound.Z)
  135.                 Box.vPosBound.Z = BrushBox.vPosBound.Z;
  136.         }
  137.     }
  138.  
  139.     void CullEntity(CFrustum *Frustum)
  140.     {
  141.         bCulled = false;
  142.         for(int i = 0; i < Brushes->Count; i++)
  143.         {
  144.             bCulled |= static_cast<CBrush*>(Brushes->get_Item(i))->CullBrush(Frustum);
  145.         }
  146.     }
  147.  
  148.     void UpdateTexCoords(CTextureManager *TextureManager)
  149.     {
  150.         for(int i = 0; i < Brushes->Count; i++)
  151.         {
  152.             static_cast<CBrush*>(Brushes->get_Item(i))->UpdateTedCoords(TextureManager);
  153.         }
  154.     }
  155.  
  156.     void DrawEntityTextured()
  157.     {
  158.         if(false)//bCulled)
  159.             return;
  160.  
  161.         for(int i = 0; i < Brushes->Count; i++)
  162.         {
  163.             static_cast<CBrush*>(Brushes->get_Item(i))->DrawBrushTextured();
  164.         }
  165.     }
  166.  
  167.     void DrawEntitySolid()
  168.     {
  169.         if(false)//bCulled)
  170.             return;
  171.  
  172.         for(int i = 0; i < Brushes->Count; i++)
  173.         {
  174.             static_cast<CBrush*>(Brushes->get_Item(i))->DrawBrushSolid();
  175.         }
  176.     }
  177.  
  178.     void DrawEntityWireFrame()
  179.     {
  180.         if(false)//bCulled)
  181.             return;
  182.  
  183.         for(int i = 0; i < Brushes->Count; i++)
  184.         {
  185.             static_cast<CBrush*>(Brushes->get_Item(i))->DrawBrushWireFrame();
  186.         }
  187.     }
  188.  
  189.     void DrawEntityPoints()
  190.     {
  191.         if(false)//bCulled)
  192.             return;
  193.  
  194.         for(int i = 0; i < Brushes->Count; i++)
  195.         {
  196.             static_cast<CBrush*>(Brushes->get_Item(i))->DrawBrushPoints();
  197.         }
  198.     }
  199.  
  200.     void Highlight(bool bPrepared)
  201.     {
  202.         if(!bPrepared)
  203.         {
  204.             PrepareHighlight();
  205.         }
  206.  
  207.         for(int i = 0; i < Brushes->Count; i++)
  208.         {
  209.             static_cast<CBrush*>(Brushes->get_Item(i))->Highlight(true);
  210.         }
  211.     }
  212.  
  213.     void Outline()
  214.     {
  215.         for(int i = 0; i < Brushes->Count; i++)
  216.         {
  217.             static_cast<CBrush*>(Brushes->get_Item(i))->Outline();
  218.         }
  219.     }
  220. };